package com.cib.process.chat.service.parser;

import com.cib.process.bean.CheckType;
import com.cib.process.bean.IvrReturnCode;
import com.cib.process.bean.NGDStartResult;
import com.cib.process.bean.ServiceResult;
import com.cib.process.chat.bean.PlayType;
import com.cib.process.chat.bean.TTSActionResult;
import com.cib.process.chat.service.ServiceResultParser;
import com.cib.process.util.LoggerHelper;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import sun.net.idn.Punycode;

@Service
public class FirstEachResultParser implements ServiceResultParser<NGDStartResult> {
//    @Value()
    private String canbreak;
    private CheckType recordflag;
    private String poundflag;

    @Override
    public ServiceResult parseResult(NGDStartResult startResult, String sessionId, String userId) {
        //null或状态码不等于200
        if (startResult==null){
            LoggerHelper.err(this.getClass(),"[sessionId:{}] [userId:{}] ngd start result empty",sessionId,userId);
            return ServiceResult.buildFailedResult(IvrReturnCode.START_SERV_REQ_ERROR);

        }else if(startResult.getCode()!=200){
            return ServiceResult.buildFailedResult(IvrReturnCode.START_SERV_REQ_ERROR);
        }else{
            NGDStartResult.StartData data = startResult.getData();
            //注意，如果有的话会透传过来
            String sessionId1 = data.getSessionId();
            String welcome = data.getWelcome();
            LoggerHelper.info(this.getClass(),"[sessionId:{}] [userId:{}] [welcome:{}]",sessionId,userId,welcome);

            //返回欢迎语同时调用tts指令
            TTSActionResult result = new TTSActionResult();
            result.setCanbreak(canbreak);
            result.setContext("<speak>"+welcome+"</speak>");
            result.setType(PlayType.TTS);
            result.setPoundflag(poundflag);
            result.setRecordflag(recordflag);
            return ServiceResult.buildSuccessResult(result,sessionId1);

        }
    }
}
